#!/usr/bin/python
"""Search for motifs begins from here."""

import sys
from alignment import Alignment
from sequence import Sequence

a = Alignment(sys.argv[1])
d = (int)(sys.argv[2])
n = 600
l = 15

# now turn for n-l+1 l-mers in first sequence
l_mers1 = []
l_mers2 = []

seq1 = a.sequences[0]
seq2 = a.sequences[1]

for i in xrange(n-l+1):
    l_mer = seq1[i:i+l]
    l_mers1.append(l_mer)
    l_mer = seq2[i:i+l]
    l_mers2.append(l_mer)
    
l3 = []
# now we have all l-mers in l_mers
count = 0
for l1 in l_mers1:
    s1 = Sequence(l1)
    for l2 in l_mers2:
        s2 = Sequence(l2)
        if s1.distance(s2) <= 16:
            l3.append(l1)
            l3.append(l2)
            print s1, s2
            count += 1
            
print count

seq2 = a.sequences[2]
l_mers2 = []

count = 0

for i in xrange(n-l+1):
    l_mer = seq2[i:i+l]
    l_mers2.append(l_mer)

for l2 in l_mers2:
    s1 = Sequence(l2)
    for i in xrange(0, len(l3), 2):
        s2 = Sequence(l3[i])
        s3 = Sequence(l3[i+1])
        
        if s1.distance(s2) <= 16 and s1.distance(s3) <= 16:
            print s1, s2, s3
            count += 1
            
print count